package com.example.sources.util;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;

/**
 * Created by Administrator on 2016/9/12.
 */
public class PropertiesTest {
    public static void main(String[] args) {
        Properties prop = new Properties();
        try{
            File file = new File("c.properties");
            System.out.println(file.getAbsolutePath());
            String filepath = Thread.currentThread().getContextClassLoader().getResource("")+File.separator+"config.properties";
            filepath = filepath.substring(6);
            System.out.println(filepath);
            //读取属性文件a.properties
            InputStream in = new BufferedInputStream(new FileInputStream(filepath));
            prop.load(in);     ///加载属性列表

            Iterator<String> it=prop.stringPropertyNames().iterator();
            while(it.hasNext()){
                String key=it.next();
                System.out.println(key+":"+prop.getProperty(key));
            }
            in.close();

        }
        catch(Exception e){
            System.out.println(e);
        }
    }
}
